
package org.openeai.lite.esb.transformers;

import org.apache.log4j.Logger;
import org.mule.api.transformer.TransformerException;
import org.mule.transformer.AbstractTransformer;

public class ExceptionToString extends AbstractTransformer
{

    private Logger log = Logger.getLogger(this.getClass());

    private String errorMsg;

    @SuppressWarnings("deprecation")
    public ExceptionToString()
    {
        super();
        this.registerSourceType(Exception.class);
        this.setReturnClass(String.class);
    }

    @Override
    public Object doTransform(Object src, String encoding) throws TransformerException
    {

        if (src instanceof Exception)
        {
            errorMsg = ((Exception) src).getMessage();
        }
        else
        {
            log.error("Error transforming message content!");
            errorMsg = "GENERAL MULE ERROR";
        }

        return errorMsg;
    }

}
